package cn.rentaotao.spring.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author rtt
 * @date 2022/5/26 14:16
 */
@Component
@Aspect
public class SpittleControllerAspect {

    @Pointcut("execution(public * cn.rentaotao.spring.web.SpittleController.*(..)) && bean(spittleController)")
    public void pointCutWithBean() {}

    // @Before("pointCutWithBean()")
    // public void before(JoinPoint point) {
    //     System.out.println("前置通知");
    // }

    @Pointcut(value = "execution(public * cn.rentaotao.spring.web.SpittleController.*(int, int)) && args(start, count)", argNames = "start,count")
    public void pointCutWithArg(int start, int count) {}

    @Before(value = "pointCutWithArg(start, count)", argNames = "point, start, count")
    public void before(JoinPoint point, int start, int count) {
        System.out.println("--- Spittle 前置通知: " + point.getTarget().toString());
        System.out.println("--- start: " + start);
        System.out.println("--- count: " + count);
    }
}
